<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .on {
            background: #000;
            color: #fff;
        }
        
        input {
            color: #000;
            background: #fff;
            border: 1px solid #000;
            margin: 10px;
        }
        
        .box div {
            width: 200px;
            height: 200px;
            border: 1px solid #000;
            display: none;
            text-align: center;
            line-height: 200px;
            box-shadow: 1px 1px 10px blue;
            text-shadow: 3px 3px 3px silver;
        }
    </style>
    <script>
        //选项卡
        class Tab {
            constructor(id) {
                this.oBox = document.getElementById(id);
                this.aBtn = this.oBox.getElementsByTagName('input');
                this.aDiv = this.oBox.getElementsByTagName('div');
                this.sum = 0;
                this.init();
            }
            init() {
                for (let i = 0; i < this.aBtn.length; i++) {
                    this.aBtn[i].onclick = function() {
                        this.sum = i;
                        this.hide();
                        this.show(i);
                        document.title = this.sum;
                    }.bind(this);
                }
            }
            hide() {
                for (let i = 0; i < this.aBtn.length; i++) {
                    this.aBtn[i].className = '';
                    this.aDiv[i].style.display = 'none';
                }
            }
            show(index) {
                this.aBtn[index].className = 'on';
                this.aDiv[index].style.display = 'block';
            }
        }
        //继承
        class AutoTab extends Tab {
            constructor(id) {
                super(id);

                this.next.bind(this);
            }
            next() {
                this.sum++;
                if (this.sum == this.aBtn.length) this.sum = 0;
                this.hide();
                this.show(this.sum);
            }
        }

        window.onload = function() {
            new Tab('box');
        };
    </script>
</head>

<body>
    <div id="box" class="box">
        <input class="on" type="button" value="One">
        <input type="button" value="Two">
        <input type="button" value="Three">
        <div style="display: block;">One</div>
        <div>Two</div>
        <div>Three</div>
    </div>
</body>

</html>